package com.csu.service.serviceImpl;

import com.csu.entity.StudentEvent;
import com.csu.entity.User;
import com.csu.mapper.StudentEventMapper;
import com.csu.mapper.UserMapper;
import com.csu.service.StudentEventService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class StudentEventServiceImpl implements StudentEventService {
    @Autowired
    private StudentEventMapper studentEventMapper;
    @Autowired
    private UserMapper userMapper;

    /**
     * 获取所有学生活动列表
     * @return List<StudentEvent>
     */
    @Override
    public List<StudentEvent> getAllStudentEvent(int userId) {
        Integer roleId = userMapper.getRoleIdByUserId(userId);
        if (roleId == null)
            return null;
        if (roleId  == 1)
            //老师
            return studentEventMapper.getAllStudentEvent(userId);
        else{
            //家长
            Integer classId = userMapper.getClassIdByUserId(userId);
            List<Integer> teacherIds = userMapper.getTeacherIdsByClassId(classId);
            List<StudentEvent> studentEvents = new ArrayList<>();
            for (Integer teacherId : teacherIds){
                List<StudentEvent> studentEvents1 = studentEventMapper.getAllStudentEvent(teacherId);
                studentEvents.addAll(studentEvents1);
            }
            return studentEvents;
        }

    }
}
